/*
 * Copyright (C) 2009,2010,2011  Paulo Cesar Pereira de Andrade.
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * Authors:
 *	Paulo Cesar Pereira de Andrade
 */

#ifndef _essa_h
#define _essa_h

#include "etypes.h"

#define ssa_use			0	/* variable read */
#define ssa_set			1	/* value changed */
#define ssa_ptr			2	/* address taken */
#define ssa_esc			4	/* escaped pointer & non scalar access */

/*
 * Types
 */
struct essa_store_data {
    east_list_t		*list;
    elabel_t		*label;
};

struct essa_store {
    /* packed vector of essa_store_data_t objects index by ssa counter */
    essa_store_data_t	*data;

    /* first valid offset */
    eint32_t		 bot;

    /* last valid offset */
    eint32_t		 top;
};

struct essa_load_data {
    east_node_t		 *node;
    east_list_t		**lists;
    elabel_t		**labels;
    eint32_t		  offset;
#if __WORDSIZE == 64
    eint32_t		  align;
#endif
};

struct essa_load {
    /* packed vector of essa_load_data_t objects index by ssa counter */
    essa_load_data_t	*data;

    /* first valid offset */
    eint32_t		 bot;

    /* last valid offset */
    eint32_t		 top;
};

/*
 * Prototypes
 */
extern void
essa(efunction_t *function);

extern void
essa_symbol_state(efunction_t *function, elabel_t *label,
		  esymbol_t *symbol, eint32_t state);

extern void
essa_load_symbol(efunction_t *function, elabel_t *label, east_list_t *list);

extern void
essa_del_list_use(efunction_t *function, east_list_t *list);

extern void
essa_del_node_use(essa_load_t *load, east_node_t *node);

extern void
essa_store_symbol(efunction_t *function, elabel_t *label, east_list_t *list);

extern void
essa_del_list_set(efunction_t *function, east_list_t *list);

extern void
init_ssa(void);

extern void
finish_ssa(void);

#endif /* _essa_h */
